var echo = function() {} ;
//Thanks to Destroy & Dimed for the idea & Bhpsngum for code help
//Based on Team Rumble from Fortnite
var modifier = {
  map_size: 200,
  crystal_value: 0,
  max_players: 200,
  kills_to_win: 5000,
  yeet_gems: true,
  healer_button: false,
  round_timer: 60*3, // in minutes
  game_delay: 150, // in seconds
  round_ship_tier: 6,//choose from 3-7 or "random"
  gems_upon_spawning: 0,//removed
  laggy_objs: false
};

var modUtils = {
  setTimeout: function(f,time) {
    this.jobs.push({f: f,time: game.step+time});
  },
  jobs: [],
  tick: function() {
    var t = game.step;
    for (var i=this.jobs.length-1;i>=0;i--){
      var job = this.jobs[i] ;
      if (t>=job.time) {
        try {
          job.f() ;
        }
        catch (err) {
        }
        this.jobs.splice(i,1);
      }
    }
  }
};

var sendUI = function(ship, UI) {
  if (ship != null && typeof ship.setUIComponent == "function") {
    if (UI.visible || UI.visible == null) ship.setUIComponent(UI);
    else ship.setUIComponent({id: UI.id, position: [0,0,0,0], visible: false});
  }
};

var a = {};
a.H_Mercury = '{"name":"H-Mercury","level":6,"model":9,"size":2,"specs":{"shield":{"capacity":[250,400],"reload":[6,9]},"generator":{"capacity":[100,175],"reload":[45,60]},"ship":{"mass":430,"speed":[75,90],"rotation":[50,65],"acceleration":[60,100]}},"bodies":{"main":{"section_segments":8,"offset":{"x":0,"y":0,"z":20},"position":{"x":[0,0,0,0,0,0,0,0,0],"y":[-65,-70,-60,-40,0,50,110,100],"z":[0,0,0,0,0,0,0,0]},"width":[1,5,10,20,30,25,10,0],"height":[1,5,10,15,25,20,10,0],"texture":[6,4,4,63,11,63,12],"propeller":true,"laser":{"damage":[7,12],"rate":8,"type":1,"speed":[100,190],"number":1,"error":0}},"cockpit":{"section_segments":8,"offset":{"x":0,"y":-20,"z":35},"position":{"x":[0,0,0,0,0,0,0],"y":[-20,-10,0,15,25],"z":[0,0,0,0,0]},"width":[0,10,12,10,5],"height":[0,10,13,12,5],"texture":[9,9,4,4],"propeller":false},"arms":{"section_segments":8,"offset":{"x":60,"y":0,"z":-10},"position":{"x":[0,0,0,5,10,0,0,-10],"y":[-85,-70,-80,-30,0,30,100,90],"z":[0,0,0,0,0,0,0,0]},"width":[1,5,6,15,15,15,10,0],"height":[1,5,6,20,30,25,10,0],"texture":[6,4,4,4,4,4,12],"angle":1,"propeller":true,"laser":{"damage":[2,4],"rate":4,"type":1,"speed":[150,200],"number":1,"error":0}},"canon":{"section_segments":12,"offset":{"x":100,"y":27,"z":5},"position":{"x":[0,0,0,0,0,0,0],"y":[-50,-45,-20,0,20,30,40],"z":[0,0,0,0,0,0,0]},"width":[0,5,7,7,3,5,0],"height":[0,5,15,15,3,5,0],"angle":3,"laser":{"damage":[4,9],"rate":1.5,"type":1,"speed":[150,220],"number":1,"error":0},"propeller":false,"texture":[6,4,10,4,4,4]}},"wings":{"main":{"offset":{"x":0,"y":-15,"z":20},"length":[60,40],"width":[60,30,20],"angle":[-20,10],"position":[30,50,30],"texture":[11,11],"bump":{"position":30,"size":10}},"font":{"length":[60],"width":[20,15],"angle":[-10,20],"position":[-20,-40],"texture":[63],"bump":{"position":30,"size":10},"offset":{"x":0,"y":0,"z":0}},"font2":{"offset":{"x":0,"y":40,"z":8},"length":[60],"width":[20,15],"angle":[-10,20],"position":[20,40],"texture":[63],"bump":{"position":30,"size":10}}},"typespec":{"name":"H-Mercury","level":6,"model":9,"code":609,"specs":{"shield":{"capacity":[250,400],"reload":[6,9]},"generator":{"capacity":[100,175],"reload":[45,60]},"ship":{"mass":430,"speed":[75,90],"rotation":[50,65],"acceleration":[60,100]}},"shape":[2.806,2.807,2.354,2.037,1.822,4.151,4.081,3.789,3.595,3.471,3.406,4.17,4.202,4.284,4.413,4.508,4.834,4.883,4.011,4.534,4.917,4.734,3.583,3.454,4.418,4.409,4.418,3.454,3.583,4.734,4.917,4.534,4.011,4.883,4.834,4.508,4.413,4.284,4.202,4.17,3.406,3.471,3.595,3.789,4.081,4.151,1.822,2.037,2.354,2.807],"lasers":[{"x":0,"y":-2.8,"z":0.8,"angle":0,"damage":[7,12],"rate":8,"type":1,"speed":[100,190],"number":1,"spread":0,"error":0,"recoil":0},{"x":2.341,"y":-3.399,"z":-0.4,"angle":1,"damage":[2,4],"rate":4,"type":1,"speed":[150,200],"number":1,"spread":0,"error":0,"recoil":0},{"x":-2.341,"y":-3.399,"z":-0.4,"angle":-1,"damage":[2,4],"rate":4,"type":1,"speed":[150,200],"number":1,"spread":0,"error":0,"recoil":0},{"x":3.895,"y":-0.917,"z":0.2,"angle":3,"damage":[4,9],"rate":1.5,"type":1,"speed":[150,220],"number":1,"spread":0,"error":0,"recoil":0},{"x":-3.895,"y":-0.917,"z":0.2,"angle":-3,"damage":[4,9],"rate":1.5,"type":1,"speed":[150,220],"number":1,"spread":0,"error":0,"recoil":0}],"radius":4.917}}';
a.Toscain = '{"name":"Toscain","level":5,"model":8,"size":1.7,"specs":{"shield":{"capacity":[275,350],"reload":[5,8]},"generator":{"capacity":[75,100],"reload":[35,50]},"ship":{"mass":300,"speed":[80,90],"rotation":[50,80],"acceleration":[80,110]}},"bodies":{"front":{"section_segments":8,"offset":{"x":0,"y":0,"z":0},"position":{"x":[0,0,0,0,0],"y":[-100,-95,-25,0,25],"z":[0,0,0,0,0]},"width":[0,20,40,40,20],"height":[0,10,35,20,5],"texture":[63,11,2,63],"laser":{"damage":[14,30],"rate":1,"type":2,"speed":[150,200],"number":1,"recoil":50,"error":0}},"cockpit":{"section_segments":8,"offset":{"x":0,"y":0,"z":10},"position":{"x":[0,0,0,0,0],"y":[-70,-70,-25,0,100],"z":[0,0,0,0,9]},"width":[0,10,15,15,10],"height":[0,15,35,20,0],"texture":[9,9,9,4]},"lasers":{"section_segments":8,"angle":15,"offset":{"x":1,"y":-5,"z":-3},"position":{"x":[0,0,0],"y":[-90,-70,-100],"z":[0,0,0]},"width":[5,5,0],"height":[5,5,0],"texture":[6],"laser":{"damage":[3.75,6],"rate":2,"type":1,"speed":[100,130],"number":2,"angle":45,"error":0}},"motor":{"section_segments":8,"offset":{"x":0,"y":0,"z":0},"position":{"x":[0,0,0,0,0],"y":[10,20,30,100,95],"z":[0,0,0,0,0]},"width":[0,40,50,50,0],"height":[0,10,15,20,0],"texture":[63,63,10,4]},"propulsors":{"section_segments":8,"offset":{"x":25,"y":0,"z":0},"position":{"x":[0,0,0],"y":[30,105,100],"z":[0,0,0]},"width":[15,15,0],"height":[10,10,0],"propeller":true,"texture":[12]}},"wings":{"main":{"doubleside":true,"offset":{"x":30,"y":80,"z":0},"length":[70,20],"width":[80,20],"angle":[0,0],"position":[-20,0],"texture":[11],"bump":{"position":20,"size":10}},"winglets":{"doubleside":true,"offset":{"x":98,"y":81,"z":-20},"length":[20,50,20],"width":[20,35,20],"angle":[90,90,90],"position":[0,0,0,0],"texture":[63],"bump":{"position":30,"size":50}}},"typespec":{"name":"Toscain","level":5,"model":8,"code":508,"specs":{"shield":{"capacity":[275,350],"reload":[5,8]},"generator":{"capacity":[75,100],"reload":[35,50]},"ship":{"mass":300,"speed":[80,90],"rotation":[50,80],"acceleration":[80,110]}},"shape":[3.4,3.354,3.556,2.748,2.336,2.055,1.858,1.732,1.634,1.548,1.462,1.404,1.371,1.36,1.241,1.161,1.723,4.485,5.01,4.795,4.111,3.842,3.82,3.753,3.634,3.407,3.634,3.753,3.82,3.842,4.111,4.795,5.01,4.485,1.723,1.161,1.241,1.353,1.371,1.404,1.462,1.548,1.634,1.732,1.858,2.055,2.336,2.748,3.556,3.354],"lasers":[{"x":0,"y":-3.4,"z":0,"angle":0,"damage":[14,30],"rate":1,"type":2,"speed":[150,200],"number":1,"spread":0,"error":0,"recoil":50},{"x":-0.846,"y":-3.454,"z":-0.102,"angle":15,"damage":[3.75,6],"rate":2,"type":1,"speed":[100,130],"number":2,"spread":45,"error":0,"recoil":0},{"x":0.846,"y":-3.454,"z":-0.102,"angle":-15,"damage":[3.75,6],"rate":2,"type":1,"speed":[100,130],"number":2,"spread":45,"error":0,"recoil":0}],"radius":5.01}}';
var ships = [];
for (let ship in a) ships.push(a[ship]);

var vocabulary = [
  {text: "Yes", icon:"\u004c", key:"Y"},
  {text: "No", icon:"\u004d", key:"N"},
  {text: "Defend", icon:"\u0025", key:"D"},
  {text: "Kill", icon:"\u007f", key:"K"},
  {text: "Sorry", icon:"\u00a1", key:"S"},
  {text: "Thanks", icon:"\u0041", key:"X"},
  {text: "You", icon:"\u004e", key:"O"},
  {text: "Me", icon:"\u004f", key:"E"},
  {text: "No Problem", icon:"\u0047", key:"P"},
  {text: "Attack", icon:"\u0049", key:"A"},
  {text: "Help", icon:"\u004a", key:"H"},
  {text: "Hmmm?", icon:"\u004b", key:"Q"},
  {text: "GoodGame", icon:"\u00a3", key:"G"},
  {text: "Wait", icon:"\u0048", key:"T"},
  {text: "Base", icon:"\u0034", key:"B"},
  {text: "Follow", icon:"\u0050", key:"F"},
  {text: "Why?", icon:"KK", key:"I"},
  {text: "Love", icon:"\u0024", key:"L"},
  {text: "Bruh", icon:"˙ ͜ʟ˙", key:"M"},
  {text: "WTF", icon:"ಠ_ಠ", key:"W"}
];

var ships_list = [
  ["Pulse-Fighter","Side-Fighter","Shadow-X-1","Y-Defender"],
  ["Vanguard","Mercury","X-Warrior","Side-Interceptor","Pioneer","Crusader"],
  ["U-Sniper","FuryStar","T-Warrior","Aetos","Shadow X-2","Howler","Bat-Defender","Toscain"],
  ["Advanced-Fighter","Scorpion","Marauder","Condor","A-Speedster","Rock-Tower","Baracuda","O-Defender","H-Mercury"],
  ["Odyssey","Shadow X-3","Bastion","Aries"]
];

function findShipCode(name){
  for (let i=0;i<ships_list.length;i++)
  for (let j=0;j<ships_list[i].length;j++)
  if (ships_list[i][j] == name) return (i+3)*100+j+1;
  return null;
}

function shuffle(array,yeetus){
  var tmp, current, top = array.length;
  if (top) while(--top){
    current = Math.floor(Math.random()*(top+1));
    tmp = array[current];
    array[current] = array[top];
    array[top] = tmp;
  }
  if (yeetus) return array.slice(0,yeetus);
  return array;
}

function getRandByRatio(tierratio){
  let idx = Math.floor(Math.random()*101);
  for (let item of tierratio){
    if (idx >= item.r[0] && idx <= item.r[1]) return item.t;
  }
}

var chooseships,maps = [1761,1749,77,45,4360,3604,5575,4990],music = ["argon.mp3"],
tierratio = [{t:3,r:[0,6]},{t:4,r:[7,16]},{t:5,r:[17,41]},{t:6,r:[42,74]},{t:7,r:[75,100]}/*6,17,25,33,17*/];
var colors = [
  {team:"Yellow",hue:52,team2:"Purple",hue2:260},
];
if (!game.custom.ship_name){
  game.custom.ship_name = true;
  if (modifier.round_ship_tier === "random")
  modifier.round_ship_tier = getRandByRatio(tierratio);
  var tier = modifier.round_ship_tier,ship_name,rand_ships,ship_choices = 4;
  switch (modifier.round_ship_tier){
    case 3:
    case 4:
      ship_choices = 3;
      break;
    case 5:
      ship_choices = 3;
      break;
    case 7:
      ship_choices = false;
    break;
  }
  ship_name = JSON.parse(JSON.stringify(ships_list[tier-3]));
  rand_ships = JSON.parse(JSON.stringify(ships_list[tier-3])).map((n,p) => tier*100+p+1);
  chooseships = shuffle(rand_ships,ship_choices);
  shuffle(colors,false);
  colors = colors[0];
  game.custom.colors = colors;
  game.custom.ship_name = ship_name;
  game.custom.modifier = modifier;
}
colors = game.custom.colors;
modifier = game.custom.modifier;
var ship_name = game.custom.ship_name;
var teams = {
  names: [colors.team,colors.team2],
  points: [0,0],
  count: [0,0],
  ships: [[],[]],
  hues: [colors.hue,colors.hue2]
};

var maps = [
  {name: "Map", author: "Mattamore", map:
    "57475667799556745454457759999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999995775445454765599776657475\n"+
    "76466754766546567474657769999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999996775647476564566745766467\n"+
    "56465667765454644576646569999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999996564667544645456776656465\n"+
    "57457644477455666655567999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999976555666655477444675475\n"+
    "47445757465447675757778986999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999968987775757674456475754474\n"+
    "57746757777665577564679888676899777789768869667986988979987879666788689668896996 96987686979688997777779988697968678969 69969886698688766697878997988968976696886798777799867688897646577556677775764775\n"+
    "77676764764574567674676676 9 6698667786797686967969976676999697896796768 698896897 6988887986 766887788667 6897888896 798698896 8676976987969996766799697696867976877668966 9 67667647676547546746767677\n"+
    "64746746445554457674 987 7788887967699986667 88 6687997966887988  8899676798996 766767797968966776 88 677669869797767667 6998976769988  8897886697997866 88 7666899967697888877 789 47675445554464764746\n"+
    "675774444644676744479  7977798996 8 8 9 87866788999 6 98 7 97986676988897 77799 69997 7968796 988788887889 6978697 79996 99777 79888967668979 7 89 6 99988766878 9 8 8 6998977797  974447676446444477576\n"+
    "4556644646777565457 9989797887966769867997877898977669899977879869968676966977968997798678777676888668886767778768977998697796696768699689787799989667798987787997689676697887979899 7545657776464466554\n"+
    "67475565546475575566 9987                                67788 9 9876969989877896798999989                    9899998976987789899696789 9 88776                                7899 66557557464556557476\n"+
    "5547757454456445559869                       7                                                                                                            7                       9689555446544547577455\n"+
    "464574466454567567799                                                                                                                                                              997765765454664475464\n"+
    "7667555564776647 9976                                         7               7            7                7            7               7                                         6799 7466774655557667\n"+
    "6777754545464564699             7                                                                                                                                      7             9964654645454577776\n"+
    "674464564464757689          8            7                           7                                                      2     7                           7            8          986757464465464476\n"+
    "45546756454777467                                  7                               7 79579568694         7687858986578                              7                                  76477745465764554\n"+
    "5545755455777769                                                                9665695654777958        846494545694647586                                                              9677775545575455\n"+
    "6674745647575898       7          7            8           97976585787678744457476686856545898677      4648567968868778757785879545574969               8            7          7       8985757465474766\n"+
    "55666666 988 86        7                      757455865879445698877998694485797688757697567694569      668748987899547968469896959499964647746495                               7        68 889 66666655\n"+
    "455447766797888   8                      844478565674698774849795444444549947598966649758779989955     46869977897887989946757669757955848444887965766444                            8   888797667744554\n"+
    "76999677886867                       7768865786644976594985984468989467778998889899797979978889867     866588799797979989888998787777779796484488644986777578484589474                    76868877699967\n"+
    "99997 9696776                    58998567949765497797888977979898798879799988897979988877988997978     748698897788899797988899979788978989797556654946444785646496464599867               6776969 79999\n"+
    "999 88 76 9 9               4564579876455589987878794485457769858876986898879998977898788997898568     6564879988789877944796789867757598694947659788785759867988949777755746878           9 9 67 88 999\n"+
    "9999 9778 977             784684456879679997849484456788568659954594855569586697798777889877889999     89655778988777867554695875674479556578775874775787548567889487869644598564          779 8779 9999\n"+
    "999 976978 96           98696495594878944677867679979494745478584669776949557944887889899779788585     86585977998988975585864688974998948767978689658996557477548578998988977667          69 879679 999\n"+
    "999966996 67           456696879989799546494444799657               44557479986696598889898779765       6596689898889578686                     476686549987876756455867589979785           76 699669999\n"+
    "999969878 6            44798559899779689568994                              694694567979987744746        486958997996757                                         6946777484689757            6 878969999\n"+
    "99 976896 8             65996878888                                            94975687979969848         67687979764644                                             794854789879             8 698679 99\n"+
    "9999 6868 6             64467897                 7787877                        587998498756955           8885596779465                         7787877                 79974949             6 8686 9999\n"+
    "98997899778             565777             999889877789                           657769688484             85558849469                           987778988999            7875896             87799879989\n"+
    "9996898989               5977           997877797777987                            5858984775               688669946                            789777797778799          85455               9898986999\n"+
    "6799796677                87            98898997797777                               5499448                  9999                                77779779989889            95                7766979976\n"+
    "9999888 67                              88987788877787                                                                         5457648855         78777888778988                              76 8889999\n"+
    "9999978789                              8889788888978             578469                                                   86456797576             8798888879888                              9878799999\n"+
    "9999997766                              97978987899                46485485                                             5555589877449        4       99878987979                              6677999999\n"+
    "9999987696                              89887799797                  995478897                                        8844444594899          9       79799778898                              6967899999\n"+
    "9999988879                                                844           9959874                                      77999678889           845                                                9788899999\n"+
    "99999 9998                                                46864           7985865                                   7656659979           77777                                                8999 99999\n"+
    "9999989979   7                                            5855678           549447                                 747796898           9594549           54995                            7   9799899999\n"+
    "9999977768      6                7799896977799            57879969           8479669                              447657898           89988647           66664959744457                       8677799999\n"+
    "9999997  9      94              468565967546789                 95            4899857              77             57749979            4484444            854446489846679              8       9  7999999\n"+
    "9999977886      669             4489544956955897                 646           666449          1 779977          44568797           7866747             79497767645694487            87       6887799999\n"+
    "9999977788      6859           89555888696588699                  877            66797      2    778877          455579            975675               595679898885444546          566       8877799999\n"+
    "9999997686      596494        7748889   88979989                   98458         85587           788887         4799678         87558455                67787988   9859589        78766       6867999999\n"+
    "9999998668      778885      94685667     9984796                   547499         79864         78977987        684497         9897489                 79659899     79594699      45749       8668999999\n"+
    "9999968696      8996678     85848899     89875487         9         899898        87467         77899877        494678        89658898       9         77987898     99985499     567678       6968699999\n"+
    "9999986668      5484678     7564697       9986474       7879         676788       88685         78877887       8965778       88694455      944695      8477899       7976896     779899       8666899999\n"+
    "9999986766      9696448    84457779       9899648      9798889       5766497      995945        99799799       4888999      79765475      4794449      8969989       97767578    488998       6676899999\n"+
    "9999997 88   7  8889447    7484479        8997945     798585459       477589       84586        89777798       888878       9898479      848444696     7979998        9786798    685749   7   88 7999999\n"+
    "9999978798      4979977    4498889        8776597     8574994984      879897       87984        78977987       968878       797776      6764859959     8898878        9886878    667959       8978799999\n"+
    "9999998799      5985798    5696779        7986496     447   7579       589677      89887        78899887       878898      776978      75777   765     7799897        9774895    686855       9978999999\n"+
    "9999999 77      9485579    5694998        9886679     869   94667      898977       967778      77788777      877699       747874      54697   9994    5465989        8997896   8646778       77 9999999\n"+
    "9999986868      8997989    9854998        89467       457    85674     585579       9758878     88799788     8788579       95697      85787    4675     966788        8998864   7998896       8686899999\n"+
    "9999986768      7756888    849498         846797      4769   588675     85479       79887778    98899889    87778697       97646      99457   95594     746788         899886   7448944       8676899999\n"+
    "99999879896     5796778    865588         784497     6796     74586     78599       97788778     989989     87788479       9689       4874     9456     497877         885668   65794459     69897899999\n"+
    "9999987876      4478479    866798        8896649     7748     879454    67477       96898778     888888     87785799       6797      94848     8759     4497988        898699   66997659      6787899999\n"+
    "99999787 9      9647797    799698        9775698     7565      77676    86789       87758777     797797     77786898       5778      6954      9589     6854779        896777   99497664      9 78799999\n"+
    "9999977778       967899    969589        7896449     9759      86449    85898       97857877     877778     77874789       864      75669      9498     7588987        949679   76987756      8777799999\n"+
    "99999 6787       859889     76689        9777988     5987      987889    48489     97967878      788887      87877779     9888      64779      9465     9577779        98967    49586794      7876 99999\n"+
    "9999988 67      7894999     64698        8999845     6647      775895    97779     774577        887788        779777     6468     865747      4864     7569998        68847    76497775      76 8899999\n"+
    "9999966866      67688998    89799         898544     9898      875749    55667     79996        87977978       644997     795      797578      9457     757798         77697    49984658      6686699999\n"+
    "9999967676 8    76589997    87966         877498     95589     899646     856797   97465        98899889       945879   76467      866898     94647     996478         9866     7899795     8 6767699999\n"+
    "9999996888      78678977     7698         979456     77987     878776      6467878989959        98788789       95479898787864      578678     74957     877679         8459     8478668       8886999999\n"+
    "9999966 89      78797989     6679         976456     68677     8898466     9898889978494        78777787       64898799866577     9475988     74497     876479         678      5687998       98 6699999\n"+
    "9999998 87      45998999      479         778495     47777      776445      794788899489        99988999       9749998858569      865677      78588     859877         548      8858858       78 8999999\n"+
    "99999686789     49798899      5558        994889     67997      879644      649679747575         777777        4675747675769      559878      78967     578499        9958      6548779      98768699999\n"+
    "99999879697     54699898      8877         77687     94988      887667       64556964744         999999        844746789664       675888      86588     58967         946       4579898      79697899999\n"+
    "9999977 67      4976989        8858        75848     56797      8777746       88755444567        798897        76544444478        855678      78459     94567        7548       6479567       76 7799999\n"+
    "9999997889                     7474        95859     47987      7995798        886697467455      977779      554764765549         499997      75978     89989        5977                     9887999999\n"+
    "9999996769                     7587        86748     756778     9987465         64484656645      798897      54665645764         5947899     874698     74498        7467                     9676999999\n"+
    "9999966 67                     8754        66948     468999     79787446            78665776     878878     6775669868          94468797     999565     79588        8478                     76 6699999\n"+
    "9999967867                    77866        97588     64787       98756885             454574   7474774747   475454              6494789       79557     78488        45877                    7687699999\n"+
    "9999996996                  8887888        48878     5598           5757464            67565   6776556776   56576              96865           9859     79799        8887888                  6996999999\n"+
    "9999989 68                   78877         85889     8                4475945           554   466644446664   455             48596                9     59978         77887                   86 9899999\n"+
    "9999986 78                    7788         94478                      968485786               767544445767                 9446944                      58777         8877                    87 6899999\n"+
    "9999997676                      8          66979                        9897858444            774467764477              47697748                        96789          8                      6767999999\n"+
    "99999779 9          6888                   66498                        998589995              4655445564              759969976                        67478                   8885          9 97799999\n"+
    "9999966668          7878                   89847                        787888697              5757667575             7749656787                        44487                   8789          8666699999\n"+
    "99999877999       977798                   84488                       79788677                 57666675               6496464497                       77488                   897894       99977899999\n"+
    "99999969897       759899                  879448                     888897657                   774477                  7764755488                     677978                  9986776      79896999999\n"+
    "99999996878       959888    88777887795799898456                  999797877658       78787         55         78787        88444667999                 894599899775678877788    8889959      87869999999\n"+
    "99999666766       957797    77778877896787876658                 99789895474        787877         77         778787         5549848799                674687878799877887777    7979655      66766699999\n"+
    "9999978999        757787      888888774988789476                98998876566         77787   1                  78777         97877597989               6454487889987888888      7878778       9998799999\n"+
    "999998 6899       578898         887597897775844               7779947874           87         1                 178             77596977              5465777798749788         8987444      9986 899999\n"+
    "99999796696       555987          78698878994897             8889945569                   1      7    7                          5657674888             75894987877887          7899459      69669799999\n"+
    "9999976877        797877           8884797974679         9899956947884                        9876    6789       2                 795866799989         9769897978684           7789549       7786799999\n"+
    "9999996 88 6     94557778          8897888997957        799479457575                        978789    987879                         55497888994        7646598887874          87779659     6 88 6999999\n"+
    "9999988666       56477888          995497986577        587784688878           7            7887997    7997887            7            67855877759        979689799458          88879985       6668899999\n"+
    "9999986978       74578877787       795789894549       86798878477           799          787999778    8779997872         997          954554789986       768798985658       78777887984       8796899999\n"+
    "9999998676       4669887878778     867989794977       6779949599           977         77999799888    88899799977         779          78468799679       749687986658     87787878897745      6768999999\n"+
    "55574 76546      579887777888      778987797989      4476894879          7989         7987889978        8799887897         9897         94798784899      986797787777      8887777885949     64567 47555\n"+
    "46645446776      67887988877       8765998 7777      6767947468          9788        888899777            777998888        8879          4647494499      774968998498       778889789596     67764454664\n"+
    "66455465775      76597788          84448879977       954887565         879787        9977878                8787799        787978        65657847788      74967889899          887798996     57756455466\n"+
    "5465557756       8547898           67557898899       567665477        9979898       79979778                87797997       8989799       77745666559      9765987897            89879575      6577555645\n"+
    "5565644747       7968777           77479756          468577564        7799778       7778989                  9898777       8779977        4657759647         89797477           77788887      7474465655\n"+
    "65774755676      9896977 1        77845467           574444557        778798       1998787                    787899        897877        755444475           76454877          77989599     67655747756\n"+
    "47745454577      6845997         778776646           574667475       7998999        99799                      99799       29998997       574766475           646677877         79998649     77545454774\n"+
    "5546645674   7    967788        887466447           8655666464       898889         88987                      78988        1988898       464666556            744664788        88774766  7   4765466455\n"+
    "7465746775        947779     888787864445           5776574664       798888         77778                      87777         888897       46647567             544468787888     97785799      5776475647\n"+
    "7465746775        645779     888787864445           8876574664       798888         77778                      87777         888897       46647567             544468787888     97787786      5776475647\n"+
    "5546645674   7   2796788        887466447           7655666464       898889         88987                      78988      2  988898       464666556            744664788        8877897   7   4765466455\n"+
    "47745454577       544997         778776646          5574667475       7998999        99799                      99799        9998997       574766475           646677877         7999848      77545454774\n"+
    "65774755676       999977          77845467           574444557        778798        998787                    787899        897877        755444475           76454877          7796959      67655747756\n"+
    "5565644747       6554777           77479969          797577564        7799778       7778989                  9898777       8779977        465775575          69797477           7775567       7474465655\n"+
    "5465557756       4885898           97757997577       9686654775       9979898       79979778                87797997       8989799        7745665695       786984997            8989756       6577555645\n"+
    "66455465775      55647788          68658688968       5599875655        879787        9977878                8787799        787978         5657895558      77959876779          8877587       57756455466\n"+
    "46645446776      88587988877       9875998 5587      9587947465          9788        888899777            777998888        8879         76647497956      784698997868       7788897878       67764454664\n"+
    "55574 76546      956887777888      487856595474      94798785567         7989         7987889978        8799887897         9897         45858789946      987646747677      88877778556       64567 47555\n"+
    "9999998676       4969887878778     864848999767       99899776864          977         77999799888    88899799977         779          46558799887       668857999898     877878788698        6768999999\n"+
    "9999986978       59978877787       748967599486       697987956958          799          787999778    877999787          997           84689789798       665989995777       78777889844       8796899999\n"+
    "9999988666       98597888          997888487999        88777889645            72           7887997    7997887            7            94778877784        556669754799 1        88876784       6668899999\n"+
    "9999996 88 6     76597778    2     8576756994457        79988847866                         978789    987879                          8575888997        7898954559558          87777886     6 88 6999999\n"+
    "9999976877       4559877   1   211 8886777975479         98999794458                     2    9876    6789                          89984899989         9575764499688           7786978       7786799999\n"+
    "99999796696      8859987          78766888999687             885647587                           7    7                           758756888             79979497847987          7897947      69669799999\n"+
    "999998 6899      8487898 1       887646657777689               78664569             87                      1     78             56785847               768876858858788         898668 4     9986 899999\n"+
    "9999978999       4799787      888888797788789547                95856659879        277787                    1 78777         97488868899                998489787467888888      78759787      9998799999\n"+
    "99999666766      5565797    77778877875787879547                 9858468988       1 787877         77         778787         6666498579                 57487796497877887777    79788898     66766699999\n"+
    "99999996878      6749888    88777887675799898589                  99967496988        78787         55         78787       949785468499                  86499555576578877788    88854674     87869999999\n"+
    "99999969897       559899                  877558                     4979868868                  774477                  7885588888                     754978                  99877756     79896999999\n"+
    "99999877999       789798                   88988                       555678555                57666675               6497778497                       98888                   897768       99977899999\n"+
    "9999966668          4878                   74877                        7585768777             5757667575             7799455787                        59987                   8787          8666699999\n"+
    "99999779 9          9488                   86578                        998678888              4655445564              556465799                        79678                   8888          9 97799999\n"+
    "9999997676                      8          99989                        95586659              774467764477             898668486                        58589          8                      6767999999\n"+
    "9999986 78                    7788         77988                      485966448               767544445767                87568569                      99477         8877                    87 6899999\n"+
    "9999989 68                   78877         85499     6                76869867          554   466644446664   455            597779                7     66978         77887                   86 9899999\n"+
    "9999996996                  8887888        96588     6468           7854599            67565   6776556776   56576             764948           7697     67599        8887888                  6996999999\n"+
    "9999967867                    77854        89698     44687       98794996             454574   7474774747   475454             66997789       74899     49998        88877                    7687699999\n"+
    "9999966 67                     8777        85478     566999     79788944           474665776     878878     67756678            76998797     998448     78498        5478                     76 6699999\n"+
    "9999996769                     7948        86498     864778     9985966         68654656645      798897      546656776          64548899     879648     95448        78578                    9676999999\n"+
    "9999997889                     7875        95969     94687      7997559        547947467455      977779      554764799858        9469997      77848     95789        97877                    9887999999\n"+
    "9999977 67        74989        8784        76868     56997      877584        88498444567        798897        76544468748       5898778      78579     88987        84689       9898486      76 7799999\n"+
    "99999879697       857898       886         77877     46688      886545       76748564744         999999         44746956955      8679788      84468     78867         9777      89899487     79697899999\n"+
    "99999686789       845899      8877        997999     79897      877767       89798747577         777777        477574587668      5477778      75967     956499        77595     99889855     98768699999\n"+
    "9999998 87        974999      897         778998     54577      775898      946888894789        99988999       7789998844898     7459877      74448     864577         9976     99989576      78 8999999\n"+
    "9999966 89        964989      947         977948     75977     8897789     7584679977555        78777787       69488799857767    48549988     77597     595979         78999    98979578      98 6699999\n"+
    "9999996888        574977     9584         979648     76687     875488      7547648987584        98788789       96779898786589     7697878     74657     558779         74596    77987465      8886999999\n"+
    "9999967676 8      984997     6977         874789     67789     894785      46964   97755        98899889      9689879   74795     7555998     98597     685778         88596    79999885    8 6767699999\n"+
    "9999966866        954998    76454         895757     4958      874654      665     79944        87977978      8557997     685     6754978      9797     899898         99646    89989579      6686699999\n"+
    "9999988 67        66499     74849        8996777     6967      775798      546     774877        887788       9779777     6894    4877977      6869     4759998        89657     9999768      76 8899999\n"+
    "99999 6787        84489     64949        9775489     9678      96477       878     94487878      788887      87877779     7458     745689      7479     4869779        984457    9889765      7876 99999\n"+
    "9999977778        86599    974859        7897547     6644      85857      855       68777877     877778     77878789       9578    765698      9869     6959987        987966    9987849      8777799999\n"+
    "99999787 9        88797    768698        9778549     8996      76548      976       94678777     797797     77785898       8748    599757      874     87978779        899467    7997488      9 78799999\n"+
    "9999987876        96879    857598        8897549     7994     89496       875       65888778     888888     87788799       6687     885478     596     97458988        898888    9797548      6787899999\n"+
    "99999879896       89578    874488         774857      889     96789      7786       57488778     989989     87788879       9859     897699     597     5589977         889757    8799657     69897899999\n"+
    "9999986768        48488    786998         886967      9479   765745      8568       74887778    98899889    87778697       96849     745787   9878     7568788         896789    8897594      8676899999\n"+
    "9999986868        76489    8794998        88868       877    87559      79849       5498878     88799788     8788869       98698     785677    757     4747788        8994648    9899656      8686899999\n"+
    "9999999 77        59479    7885998        9867479     785   64697       88556       449778      77788777      877749       77844      684797   965     7888989        8995447    9779954      77 9999999\n"+
    "9999998799        74498    8654779        7949978     469   47889       86679      86587        78899887       478598      778474     695694   546     4699897        9779988    8988774      9978999999\n"+
    "9999978798        67497    8957889        8747787     7874994787       77998       88789        78977987        98578       744867     97595975998     8499878        9884477    7978865      8978799999\n"+
    "9999997 88   7    49877    9657479        8978979     788844449        97479       9968         89777798       268978       986668      4789569657     5549998        9785997    7777845  7   88 7999999\n"+
    "9999986766        55788    89474579       9876498      5589957        898468      98484         99799799 1      685799      7976849      67945795      4499989       97787984    887744       6676899999\n"+
    "9999986668        69888     6599767       9957678       44755         56689       89968         78877887        768778       887945       485476       4947899       7974545     889555       8666899999\n"+
    "9999968696        98998     87596799     89866687         9          77574        88547 1       77899877         95978        888844         9         59777898     99976978     898746       6968699999\n"+
    "9999998668       29699      99445888     9656789                    74669         47958         78977987         96897         997874                  86899899     79589999      99668       8668999999\n"+
    "9999997686        8588         968468   88956676                   88658         85895           788887          867578         55646                  547887988   95599566       87469       6867999999\n"+
    "9999977788        78           95997487898547746                   99            45768   1      2778877          956979            57696                544699444558665787          969       8877799999\n"+
    "9999977886        7             8447754999574579                 867           865598            779977           4886997           57456               95765848998548746            78       6887799999\n"+
    "9999997  9                      987689566986648                 45            486797               77              7488679            6778               969565545666969              9       9  7999999\n"+
    "9999977768      2                7799756878599                9484           989595                                55959968           65799               9998795866977                       8677799999\n"+
    "9999989979   7                        498547                84677           477884                                  86889477           48477                                              7   9799899999\n"+
    "99999 9998                                                78964           46667471                                   759844755           88947                                                8999 99999\n"+
    "9999988879                                                896           8648866                                         98888659           758                                                9788899999\n"+
    "9999987696                              89887799797                  99446966      1                                       78884756                  79799778898                              6967899999\n"+
    "9999997766                              97978987899                88869695                                                   9974487                99878987979                              6677999999\n"+
    "9999978789                              8889788888978             658479       1                                                 89555             8798888879888                              9878799999\n"+
    "9999888 67                              88987788877787                                                                                            78777888778988                              76 8889999\n"+
    "6799796677                87            98898997797777                        2       576878                  6579                                77779779989889            78                7766979976\n"+
    "9996898989               8977           997877797777987                             767448575               88799448                             789777797778799           7798               9898986999\n"+
    "98997899778             897777             999889877789                            78874577648             45859886899                           987778988999             777798             87799879989\n"+
    "9999 6868 6             67887897                 7787877                         98798974897649           4468664484448                         7787877                 79878879             6 8686 9999\n"+
    "99 976896 8             49897878888                                             798698997965488          889888797879694                                             88887879848             8 698679 99\n"+
    "999969878 6            958988898997798                                       9449457844998767658        56859589979487849                                         897799898888565            6 878969999\n"+
    "999966996 67           6948484599897989987997                      46656685674468757458989874757       64949789898889545954            1                   7997899897989979797658           76 699669999\n"+
    "999 976978 96          58589477689577787898999788787797889979546778457769679789764848989977978867     598977977998988448698588   989887977797998879778788799989878777878966996846          69 879679 999\n"+
    "9999 9778 977           6785569779458787999789789777999797797786557756669765549959877788987786847     6797487789887778689986878788779898888797797999777987987999787785674976478            779 8779 9999\n"+
    "999 88 76 9 9                84769675989888998787878879978888868778477989887999897789878899787759     487898799887898779745467898977988799788887997887878789988845789957889489             9 9 67 88 999\n"+
    "99997 9696776                    6575694678569566999788897797989879887979998889797998887798885948     64649988977888997979888899797889789897749747445595889944764885797944                 6776969 79999\n"+
    "76999677886867                     49767655577799999584596975485568847687899888989979797997858568     84698887997979799898889987477847588899546566477996586475978974949                   76868877699967\n"+
    "455447766797888   8                   94757474489848565556456477588466665674464847468686766589877     785769977897887988987794764444699647754854948596575998894488                   8   888797667744554\n"+
    "55666666 988 86        7                         54957474954667844895545779998546949474958894597       98459448789977548968794887597679467759                                   7        68 889 66666655\n"+
    "6674745647575898       7          7            8                     797995496669589544475566979       9765879795868785995569897849                     8            7          7       8985757465474766\n"+
    "5545755455777769                                                                      879757967         85856476986945899877                                                            9677775545575455\n"+
    "45546756454777467                                  7                               7                         74599847                               7                                  76477745465764554\n"+
    "674464564464757689          8            7                           7                                                            7                           7            8          986757464465464476\n"+
    "6777754545464564699             7                                                                                                                                      7             9964654645454577776\n"+
    "7667555564776647 9976                                         7               7            7                7            7               7                                         6799 7466774655557667\n"+
    "464574466454567567799                                                                                                                                                              997765765454664475464\n"+
    "5547757454456445559869                       7                                                                                                            7                       9689555446544547577455\n"+
    "67475565546475575566 9987                                67788 9 9876969989877896798999989                    9899998976987789899696789 9 88776                                7899 66557557464556557476\n"+
    "4556644646777565457 9989797887966769867997877898977669899977879869968676966977968997798678777676888668886767778768977998697796696768699689787799989667798987787997689676697887979899 7545657776464466554\n"+
    "675774444644676744479  7977798996 8 8 9 87866788999 6 98 7 97986676988897 77799 69997 7968796 988788887889 6978697 79996 99777 79888967668979 7 89 6 99988766878 9 8 8 6998977797  974447676446444477576\n"+
    "64746746445554457674 987 7788887967699986667 88 6687997966887988  8899676798996 766767797968966776 88 677669869797767667 6998976769988  8897886697997866 88 7666899967697888877 789 47675445554464764746\n"+
    "77676764764574567674676676 9 6698667786797686967969976676999697896796768 698896897 6988887986 766887788667 6897888896 798698896 8676976987969996766799697696867976877668966 9 67667647676547546746767677\n"+
    "57746757777665577564679888676899777789768869667986988979987879666788689668896996 96987686979688997777779988697968678969 69969886698688766697878997988968976696886798777799867688897646577556677775764775\n"+
    "47445757465447675757778986999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999968987775757674456475754474\n"+
    "57457644477455666655567999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999976555666655477444675475\n"+
    "56465667765454644576646569999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999996564667544645456776656465\n"+
    "76466754766546567474657769999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999996775647476564566745766467\n"+
    "57475667799556745454457759999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999995775445454765599776657475",
  shipspawn: [{x:-550,y:0},{x:550,y:0}],
  radar: {type:"round",width:10*2,height:10*2}},
  {name: "Croszair", author: "rob0nuko", map:
    "99  9999   99  9489                        955639                             98999997  999999999999999999999999  79999989                             936559                        9849  99   9999  99\n"+
    "999  9899   9999459                       966579                                   9888                          8889                                   975669                       9549999   9989  999\n"+
    " 999  9349   96479                       965499           9998879                   79897898797777799777779789879897                   9788999           994569                       97469   9439  999 \n"+
    "  999  9799  9449          9988788777999845899           86644349                     7797787988899999988897877977                     94344668           9985489997778878899          9449  9979  999  \n"+
    "9  999  93999379          9886368763543563899           93758368977987988877                    87899878                    77888978977986385739           9983653453678636889          97399939  999  9\n"+
    "99  99  9943799          9988799845775638349           9777764484878384576739                     7777                     9376754838784844677779           9438365775489978899          9973499  99  99\n"+
    "499      93559                   93346674458           88563455636864678465779                     55                     97756487646863655436588           85447664339                   95539      994\n"+
    "9599      9739                    9437757798           789787789799999365466398                    44                    893664563999997987787987           8977577349                    9379      9959\n"+
    " 94599    9679                     897634697                          9367745859                   44                   9585477639                          796436798                     9769    99549 \n"+
    "  97799   9359                      97844849                           9466656868                  22                  8686566649                           94844879                      9539   99779  \n"+
    "   98599999399                       8676689                            9667368739                 55                 9378637669                            9866768                       99399999589   \n"+
    "9   9675753749    987797799           877689                             9366463738                22                8373646639                             986778           997797789    9473575769   9\n"+
    "99  9435753849   788585648699          83548                              9537675698            98777789            8965767359                              84538          996846585887   9483575349  99\n"+
    "99999767748839   9594883585359          9889                               9877995339            979979            9335997789                               9889          9535853884959   93884776799999\n"+
    " 9476355899999   77878995633539                                                  94549                            94549                                                  93533659987877   9999985536749 \n"+
    " 98586389               94655497                                                  9454987                      7894549                                                  79455649               98368589 \n"+
    "99856649                 93355788                                                  975467                      764579                                                  88755339                 94665899\n"+
    "9976539         4     4   7788779                                                   87349                      94378                                                   9778877   4     4         9356799\n"+
    "993859      7                                 988787887899899898799888899            9998                      8999            998888997898998998788787889                                 7      958399\n"+
    "99589   5     3     7   6                    99838746337347875465579765789                                                    98756797556457874373364783899                    6   7     3     5   98599\n"+
    "99659    6    6   3                         7996336564336445364458544438359                                                  9538344458544635446334656336997                         3   6    6    95699\n"+
    "99549  7  3       6  67  4 3               996663585585469979877899993477879                                                978774399998778979964585585366699               3 4  76  6       3  7  94599\n"+
    "99739  3    546    636       4            99543489797999988998898899993678549                                              94587639999889889988999979798434599            4       636    645    3  93799\n"+
    "99959     5  5           3  5            9436888   4555               94476749                                            94767449               5554   8886349            5  3           5  5     95999\n"+
    "99979     4     7                       9367539    4478                96746869             9787987777897879             96864769                8744    9357639                       7     4     97999\n"+
    "99659  4  6            5    7   4       745869     4447                 97798789             95443566534459             98789779                 7444     968547       4   7    5            6  4  95699\n"+
    "99769            4   7 6                84647      7677                                       837867768738                                       7767      74648                6 7   4            96799\n"+
    "995696       6   73      3              9538       3644                                        9377337739                                        4463       8359              3      37   6       696599\n"+
    "99869                          4        869        8989                                         86377368                                         9898        968        4                          96899\n"+
    "99669     5         6    33             79        97568                                          954459                                          86579        97             33    6         5     96699\n"+
    "99679 3     5         46                9        833738                                           9559                                           837338        9                64         5     3 97699\n"+
    "99389   3                                       8373859                                            99                                            9583738                                       3   98399\n"+
    "99879            4         5                   96757659                                                                                          95675769                   5         4            97899\n"+
    "99969    5      3                             766783567                                987779              977789                                765387667                             3      5    96999\n"+
    "99979        7               4               9365456777            8988779899989        977489            984779        9899989778898            7776545639               4               7        97999\n"+
    "99989  6    6                               86458667839          7747845638438379        756858          858657        9738348365487477          93876685468                               6    6  98999\n"+
    "99669            3  787777         9       976569798998         965557634444748749        743369        963347        947847444436755569         899897965679       9         777787  3            96699\n"+
    "99659        6      836769        99      837639 463556        94387568699999999999        988979      979889        99999999999686578349        655364 936738      99        967638      6        95699\n"+
    "99759999    3       943467       959     776469  734466        868677999                                                        999776868        664437  964677     959       764349       3    99995799\n"+
    "99854639         5  777647      9547    985658   664456       84865559                                                            95556848       654466   856589    7459      746777  5         93645899\n"+
    "99558539            943859      9448   956377    536543       8658469                                                              9648568       345635    773659   8449      958349            93585599\n"+
    "99679999   6        765587      9669  766539     576474       9358879    9 9 9 9 9 9 9 9 9 9 9 9        9 9 9 9 9 9 9 9 9 9 9 9    9788539       474675     935667  9669      785567        6   99997699\n"+
    "99389443            958839      9787 978548      487535       8373778                                                              8773738       535784      845879 7879      938859            34498399\n"+
    "993892232           946769      7379794659       777576       9858757   9 9 9 9 9 9 9 9 9 9 9 9    99    9 9 9 9 9 9 9 9 9 9 9 9   7578589       675777       9564979737      967649           232298399\n"+
    "994695222          9859539      944456889        574785       9773448                                                              8443779       587475        988654449      9359589          222596499\n"+
    "99459434          84645837      77653589         744755       7387569    9 9 9 9 9 9 9 9 9 9 9 9        9 9 9 9 9 9 9 9 9 9 9 9    9657837       557447         98535677      73854648          43495499\n"+
    "99879999         958845557      8873879         7999999       7766358                                                              8536677       9999997         9783788      755548859         99997899\n"+
    "99486549        7464545937      749367         99655569       7668467   9 9 9 9 9 9 9 9 9 9 9 9    99    9 9 9 9 9 9 9 9 9 9 9 9   7648667       96555699         763947      7395454647        94568499\n"+
    "99646779       74484746389      88449         956546638       9898648                                                              8468989       836645659         94488      98364748447       97764699\n"+
    "99549999       7758459768       7767         9665543769       9793989    9 9 9 9 9 9 9 9 9 9 9 9        9 9 9 9 9 9 9 9 9 9 9 9    9893979       9673455669         7677       8679548577       99994599\n"+
    "79549352       867588589        948         9349855839         987969                                                              969789         9385589439         849        985885768       25394597\n"+
    "998792445      88534337         79         9589343779           849538  9 9 9 9 9 9 9 9 9 9 9 9    99    9 9 9 9 9 9 9 9 9 9 9 9  835948           9773439859         97         73343588      544297899\n"+
    "993695422      8867379          9         9639387559             96539                                                            93569             9557839369         9          9737688      224596399\n"+
    "89859323       749579                    9883534379               8349   9 9 9 9 9 9 9 9 9 9 9 9        9 9 9 9 9 9 9 9 9 9 9 9   9438               9734353889                    975947       32395898\n"+
    "79779999       959678                   9766933889                 967                                                            769                 9883396679                   876959       99997797\n"+
    "99444369       874647                  9558978549                   89  9 9 9 9 9 9 9 9 9 9 9 9    99    9 9 9 9 9 9 9 9 9 9 9 9  98                   9458798559                  746478       96344499\n"+
    "79763469       875979                 9385785749                     9                                                            9                     9475875839                 979578       96436797\n"+
    "99439999       874939                9654464849                                                                                                          9484644569                939478       99993499\n"+
    "99669454       754957               9536476589                                                                                                            9856746359               759457       45496699\n"+
    "997692252      864867              9536486759                                                                                                              9576846359              768468      252296799\n"+
    "993595242      784369             7933669759                                     787778878                    878877787                                     9579663397             963487      242595399\n"+
    "99659354       837558            9584446459            9      999                 97456337                    73365479                 999      9            9546444859            855738       45395699\n"+
    "99589999       883768           7666434799            99      9899                 9866747787798977887798977877476689                 9989      99            9974346667           867388       99998599\n"+
    "99846589        83759          9535563359            939      98749                 89443668538383766738383586634498                 94789      939            9533655359          95738        98564899\n"+
    "99636659         7758         9444433759            9569      987899                 897789998487874478784899987798                 998789      9659            9573344449         8577         95663699\n"+
    "99659999      2   879        9587653569            97888      9688339                        96365766756369                        9338869      88879            9653567859        978   2      99995699\n"+
    "99869324           89       9453433789             96659      97354659                        967545545769                        95645379      95669             9873343549       98           42396899\n"+
    "99449242            7       777637579              93938      967564599                        9547337459                        995465769      83939              975736777       7            24294499\n"+
    "977592252   4               94658769               97938      9684875469                        87755778                        9645784869      83979               96785649               4   252295779\n"+
    "995594244                   8733579                96797      77897375399                       95333359                       99357379877      79769                9753378                   442495599\n"+
    "996694355                   973379            9    96977           9336398                999   97844879   999                8936339           77969    9            973379                   553496699\n"+
    "9968952455   2              85579            99    99464            9636699            999357   73855837   753999            9966369            46499    99            97558              2   5542598699\n"+
    "9934925424       7          9588            849    97343             986549999       99547538   99888899   83574599       999945689             34379    948            8859          7       4245294399\n"+
    "9978999999     3 99         8667           7659    37363              957435368     983545787   94788749   787545389     863534759              36373    9567           7668         99 3     9999998799\n"+
    "9937333569       859        9537          97959    75757               996778678    935774348   79877897   843477539    876877699               75757    95979          7359        958       9653337399\n"+
    "9937644459       8387       7637         966789    24354                955478469    93366799      99      99766339    964874559                45342    987669         7367       7838       9544467399\n"+
    "9963355559  5    9878       7688        8358699    56549                9395858468    95397        99        79359    8648585939                94565    9968538        8867       8789    5  9555533699\n"+
    "9983736569       9637       9439       97764749    63599                95388775389    77          99          77    98357788359                99536    94746779       9349       7369       9656373899\n"+
    "9933577939       9648       9648       7383367     55989                 79657678477               99               77487675697                 98955     7633837       8469       8469       9397753399\n"+
    "9744964459       9357       7649       766669      79379                  77334656899              99              99865643377                  97397      966667       9467       7539       9544694479\n"+
    "9977737339       8869       7438       76889       98539                   8678776569              99              9656778768                   93589       98867       8347       9688       9337377799\n"+
    "9959483759   8   7648       9638       7697        98379                    765657769                              967756567                    97389        7967       8369       8467   8   9573849599\n"+
    "9963647549       7339       7689       9497        96549     9               96656748                              84765669               9     94569        7949       9867       9337       9457463699\n"+
    "8943335569       9578       969        8897        95549     79               9454639                              9364549               97     94559        7988        969       8759       9655333498\n"+
    "9955364499       9877       79         8697        94749     849          7    9999999                            9999999    7          948     94749        7968         97       7789       9944635599\n"+
    "997743639     5  9437       9          9639        95389     7639        949        999                          999        949        9367     98359        9369          9       7349  5     936347799\n"+
    "998755999        8878                  7877        98569     76359       7489        999                        999        9847       95367     96589        7787                  8788        999557899\n"+
    "9975749   4      8837                799657        83579     789779     993669        99                        99        966399     977987     97538        756997                7388      4   9475799\n"+
    "9999999          9539                788349        88759                945859                                            958549                95788        943887                9359          9999999\n"+
    "7888884       5  7547                749857        78379                935739                                            937539                97387        758947                7457  5       4888887\n"+
    "7867685  4  7    7839                859359        933799              7755577                                            7755577              997339        953958                9387    7  4  5867687\n"+
    "8688686          7757                999999        9783999             937569                                              965739             9993879        999999                7577          6868868\n"+
    "5847786          9569                              98877 99            979989                                              989979            99 77889                              9659          6877485\n"+
    "8767885   5  79988547                              976664599                                    2 3993 2                                    995466679                              74588997  5   5887678\n"+
    "8853377 3    6738668                                934667967                                  3 339933 3                                  769766439                                8668376    3 7733588\n"+
    "6686836      575359                                  956996653                                253224422352                                356699659                                  953575      6386866\n"+
    "8856785    7 49749                                    999745324999878978879                   2 11311311 2                   978879878999423547999                                    94794 7    5876588\n"+
    "7668765      5898          9999999999                  95355659976376345438                  21171544517112                  83454367367995655359                  9999999999          8985      5678667\n"+
    "8868675   4  4665         96653786879                   5522797368447536688                   13113  31131                   8866357448637972255                   97868735669         5664  4   5768688\n"+
    "5668786 7    4744        964783557569                    25497777885483645999999             99363 44 36399             99999954638458877779452                    965755387469        4474    7 6878665\n"+
    "5668786 7    4744        964783557569                    25497777885483645999999             99363 44 36399             99999954638458877779452                    965755387469        4474    7 6878665\n"+
    "8868675   4  4665         96653786879                   5522797368447536688                   13113  31131                   8866357448637972255                   97868735669         5664  4   5768688\n"+
    "7668765      5898          9999999999                  95355659976376345438                  21171544517112                  83454367367995655359                  9999999999          8985      5678667\n"+
    "8856785    7 49749                                    999745324999878978879                   2 11311311 2                   978879878999423547999                                    94794 7    5876588\n"+
    "6686836      575359                                  956996653                                253224422352                                356699659                                  953575      6386866\n"+
    "8853377 3    6738668                                934667967                                  3 339933 3                                  769766439                                8668376    3 7733588\n"+
    "8767885   5  79988547                              976664599                                    2 3993 2                                    995466679                              74588997  5   5887678\n"+
    "5847786          9569                              98877 99            979989                                              989979            99 77889                              9659          6877485\n"+
    "8688686          7757                999999        9783999             937569                                              965739             9993879        999999                7577          6868868\n"+
    "7867685  4  7    7839                859359        933799              7755577                                            7755577              997339        953958                9387    7  4  5867687\n"+
    "7888884       5  7547                749857        78379                935739                                            937539                97387        758947                7457  5       4888887\n"+
    "9999999          9539                788349        88759                945859                                            958549                95788        943887                9359          9999999\n"+
    "9975749   4      8837                799657        83579     789779     993669        99                        99        966399     977987     97538        756997                7388      4   9475799\n"+
    "998755999        8878                  7877        98569     76359       7489        999                        999        9847       95367     96589        7787                  8788        999557899\n"+
    "997743639     5  9437       9          9639        95389     7639        949        999                          999        949        9367     98359        9369          9       7349  5     936347799\n"+
    "9955364499       9877       79         8697        94749     849          7    9999999                            9999999    7          948     94749        7968         97       7789       9944635599\n"+
    "8943335569       9578       969        8897        95549     79               9454639                              9364549               97     94559        7988        969       8759       9655333498\n"+
    "9963647549       7339       7689       9497        96549     9               96656748                              84765669               9     94569        7949       9867       9337       9457463699\n"+
    "9959483759   8   7648       9638       7697        98379                    765657769                              967756567                    97389        7967       8369       8467   8   9573849599\n"+
    "9977737339       8869       7438       76889       98539                   8678776569              99              9656778768                   93589       98867       8347       9688       9337377799\n"+
    "9744964459       9357       7649       766669      79379                  77334656899              99              99865643377                  97397      966667       9467       7539       9544694479\n"+
    "9933577939       9648       9648       7383367     55989                 79657678477               99               77487675697                 98955     7633837       8469       8469       9397753399\n"+
    "9983736569       9637       9439       97764749    63599                95388775389    77          99          77    98357788359                99536    94746779       9349       7369       9656373899\n"+
    "9963355559  5    9878       7688        8358699    56549                9395858468    95397        99        79359    8648585939                94565    9968538        8867       8789    5  9555533699\n"+
    "9937644459       8387       7637         966789    24354                955478469    93366799      99      99766339    964874559                45342    987669         7367       7838       9544467399\n"+
    "9937333569       859        9537          97959    75757               996778678    935774348   79877897   843477539    876877699               75757    95979          7359        958       9653337399\n"+
    "9978999999     3 99         8667           7659    37363              957435368     983545787   94788749   787545389     863534759              36373    9567           7668         99 3     9999998799\n"+
    "9934925424       7          9588            849    97343             986549999       99547538   99888899   83574599       999945689             34379    948            8859          7       4245294399\n"+
    "9968952455   2              85579            99    99464            9636699            999357   73855837   753999            9966369            46499    99            97558              2   5542598699\n"+
    "996694355                   973379            9    96977           9336398                999   97844879   999                8936339           77969    9            973379                   553496699\n"+
    "995594244                   8733579                96797      77897375399                       95333359                       99357379877      79769                9753378                   442495599\n"+
    "977592252   4               94658769               97938      9684875469                        87755778                        9645784869      83979               96785649               4   252295779\n"+
    "99449242            7       777637579              93938      967564599                        9547337459                        995465769      83939              975736777       7            24294499\n"+
    "99869324           89       9453433789             96659      97354659                        967545545769                        95645379      95669             9873343549       98           42396899\n"+
    "99659999      2   879        9587653569            97888      9688339                        96365766756369                        9338869      88879            9653567859        978   2      99995699\n"+
    "99636659         7758         9444433759            9569      987899                 897789998487874478784899987798                 998789      9659            9573344449         8577         95663699\n"+
    "99846589        83759          9535563359            939      98749                 89443668538383766738383586634498                 94789      939            9533655359          95738        98564899\n"+
    "99589999       883768           7666434799            99      9899                 9866747787798977887798977877476689                 9989      99            9974346667           867388       99998599\n"+
    "99659354       837558            9584446459            9      999                 97456337                    73365479                 999      9            9546444859            855738       45395699\n"+
    "993595242      784369             7933669759                                     787778878                    878877787                                     9579663397             963487      242595399\n"+
    "997692252      864867              9536486759                                                                                                              9576846359              768468      252296799\n"+
    "99669454       754957               9536476589                                                                                                            9856746359               759457       45496699\n"+
    "99439999       874939                9654464849                                                                                                          9484644569                939478       99993499\n"+
    "79763469       875979                 9385785749                     9                                                            9                     9475875839                 979578       96436797\n"+
    "99444369       874647                  9558978549                   89  9 9 9 9 9 9 9 9 9 9 9 9    99    9 9 9 9 9 9 9 9 9 9 9 9  98                   9458798559                  746478       96344499\n"+
    "79779999       959678                   9766933889                 967                                                            769                 9883396679                   876959       99997797\n"+
    "89859323       749579                    9883534379               8349   9 9 9 9 9 9 9 9 9 9 9 9        9 9 9 9 9 9 9 9 9 9 9 9   9438               9734353889                    975947       32395898\n"+
    "993695422      8867379          9         9639387559             96539                                                            93569             9557839369         9          9737688      224596399\n"+
    "998792445      88534337         79         9589343779           849538  9 9 9 9 9 9 9 9 9 9 9 9    99    9 9 9 9 9 9 9 9 9 9 9 9  835948           9773439859         97         73343588      544297899\n"+
    "79549352       867588589        948         9349855839         987969                                                              969789         9385589439         849        985885768       25394597\n"+
    "99549999       7758459768       7767         9665543769       9793989    9 9 9 9 9 9 9 9 9 9 9 9        9 9 9 9 9 9 9 9 9 9 9 9    9893979       9673455669         7677       8679548577       99994599\n"+
    "99646779       74484746389      88449         956546638       9898648                                                              8468989       836645659         94488      98364748447       97764699\n"+
    "99486549        7464545937      749367         99655569       7668467   9 9 9 9 9 9 9 9 9 9 9 9    99    9 9 9 9 9 9 9 9 9 9 9 9   7648667       96555699         763947      7395454647        94568499\n"+
    "99879999         958845557      8873879         7999999       7766358                                                              8536677       9999997         9783788      755548859         99997899\n"+
    "99459434          84645837      77653589         744755       7387569    9 9 9 9 9 9 9 9 9 9 9 9        9 9 9 9 9 9 9 9 9 9 9 9    9657837       557447         98535677      73854648          43495499\n"+
    "994695222          9859539      944456889        574785       9773448                                                              8443779       587475        988654449      9359589          222596499\n"+
    "993892232           946769      7379794659       777576       9858757   9 9 9 9 9 9 9 9 9 9 9 9    99    9 9 9 9 9 9 9 9 9 9 9 9   7578589       675777       9564979737      967649           232298399\n"+
    "99389443            958839      9787 978548      487535       8373778                                                              8773738       535784      845879 7879      938859            34498399\n"+
    "99679999   6        765587      9669  766539     576474       9358879    9 9 9 9 9 9 9 9 9 9 9 9        9 9 9 9 9 9 9 9 9 9 9 9    9788539       474675     935667  9669      785567        6   99997699\n"+
    "99558539            943859      9448   956377    536543       8658469                                                              9648568       345635    773659   8449      958349            93585599\n"+
    "99854639         5  777647      9547    985658   664456       84865559                                                            95556848       654466   856589    7459      746777  5         93645899\n"+
    "99759999    3       943467       959     776469  734466        868677999                                                        999776868        664437  964677     959       764349       3    99995799\n"+
    "99659        6      836769        99      837639 463556        94387568699999999999        988979      979889        99999999999686578349        655364 936738      99        967638      6        95699\n"+
    "99669            3  787777         9       976569798998         965557634444748749        743369        963347        947847444436755569         899897965679       9         777787  3            96699\n"+
    "99989  6    6                               86458667839          7747845638438379        756858          858657        9738348365487477          93876685468                               6    6  98999\n"+
    "99979        7               4               9365456777            8988779899989        977489            984779        9899989778898            7776545639               4               7        97999\n"+
    "99969    5      3                             766783567                                987779              977789                                765387667                             3      5    96999\n"+
    "99879            4         5                   96757659                                                                                          95675769                   5         4            97899\n"+
    "99389   3                                       8373859                                            99                                            9583738                                       3   98399\n"+
    "99679 3     5         46                9        833738                                           9559                                           837338        9                64         5     3 97699\n"+
    "99669     5         6    33             79        97568                                          954459                                          86579        97             33    6         5     96699\n"+
    "99869                          4        869        8989                                         86377368                                         9898        968        4                          96899\n"+
    "995696       6   73      3              9538       3644                                        9377337739                                        4463       8359              3      37   6       696599\n"+
    "99769            4   7 6                84647      7677                                       837867768738                                       7767      74648                6 7   4            96799\n"+
    "99659  4  6            5    7   4       745869     4447                 97798789             95443566534459             98789779                 7444     968547       4   7    5            6  4  95699\n"+
    "99979     4     7                       9367539    4478                96746869             9787987777897879             96864769                8744    9357639                       7     4     97999\n"+
    "99959     5  5           3  5            9436888   4555               94476749                                            94767449               5554   8886349            5  3           5  5     95999\n"+
    "99739  3    546    636       4            99543489797999988998898899993678549                                              94587639999889889988999979798434599            4       636    645    3  93799\n"+
    "99549  7  3       6  67  4 3               996663585585469979877899993477879                                                978774399998778979964585585366699               3 4  76  6       3  7  94599\n"+
    "99659    6    6   3                         7996336564336445364458544438359                                                  9538344458544635446334656336997                         3   6    6    95699\n"+
    "99589   5     3     7   6                    99838746337347875465579765789                                                    98756797556457874373364783899                    6   7     3     5   98599\n"+
    "993859      7                                 988787887899899898799888899            9998                      8999            998888997898998998788787889                                 7      958399\n"+
    "9976539         4     4   7788779                                                   87349                      94378                                                   9778877   4     4         9356799\n"+
    "99856649                 93355788                                                  975467                      764579                                                  88755339                 94665899\n"+
    " 98586389               94655497                                                  9454987                      7894549                                                  79455649               98368589 \n"+
    " 9476355899999   77878995633539                                                  94549                            94549                                                  93533659987877   9999985536749 \n"+
    "99999767748839   9594883585359          9889                               9877995339            979979            9335997789                               9889          9535853884959   93884776799999\n"+
    "99  9435753849   788585648699          83548                              9537675698            98777789            8965767359                              84538          996846585887   9483575349  99\n"+
    "9   9675753749    987797799           877689                             9366463738                22                8373646639                             986778           997797789    9473575769   9\n"+
    "   98599999399                       8676689                            9667368739                 55                 9378637669                            9866768                       99399999589   \n"+
    "  97799   9359                      97844849                           9466656868                  22                  8686566649                           94844879                      9539   99779  \n"+
    " 94599    9679                     897634697                          9367745859                   44                   9585477639                          796436798                     9769    99549 \n"+
    "9599      9739                    9437757798           789787789799999365466398                    44                    893664563999997987787987           8977577349                    9379      9959\n"+
    "499      93559                   93346674458           88563455636864678465779                     55                     97756487646863655436588           85447664339                   95539      994\n"+
    "99  99  9943799          9988799845775638349           9777764484878384576739                     7777                     9376754838784844677779           9438365775489978899          9973499  99  99\n"+
    "9  999  93999379          9886368763543563899           93758368977987988877                    87899878                    77888978977986385739           9983653453678636889          97399939  999  9\n"+
    "  999  9799  9449          9988788777999845899           86644349                     7797787988899999988897877977                     94344668           9985489997778878899          9449  9979  999  \n"+
    " 999  9349   96479                       965499           9998879                   79897898797777799777779789879897                   9788999           994569                       97469   9439  999 \n"+
    "999  9899   9999459                       966579                                   9888                          8889                                   975669                       9549999   9989  999\n"+
    "99  9999   99  9489                        955639                             98999997  999999999999999999999999  79999989                             936559                        9849  99   9999  99",
  shipspawn: [{x:-530,y:0},{x:530,y:0}],
  radar: {type:"box",width:10*1.5,height:10*2.5}},
];

game.custom.radar_background = {
  id: "radar_background",
  components: [],
};

var scale_pos = 100 / (modifier.map_size * 10);
var scale_size = 50 / modifier.map_size;
function addRadarSpot (x, y, type, width, height, alpha, color){
  game.custom.radar_background.components.push({
    type: type,
    position: [
      50+x*scale_pos-width*scale_size/2,
      50-y*scale_pos-height*scale_size/2,
      width*scale_size, height*scale_size,
    ],
    fill:`hsla(${color},100%,50%,${alpha})`
  });
}

var update = 1;
var delay = modifier.game_delay * 60;
if (!game.custom.map) game.custom.map = maps[1];
var map = game.custom.map; // for debugging
for (let i=0; i<map.shipspawn.length; i++){
  addRadarSpot(map.shipspawn[i].x,map.shipspawn[i].y,map.radar.type,map.radar.width,map.radar.height,0.3,teams.hues[i]);
  addRadarSpot(map.shipspawn[i].x,map.shipspawn[i].y,map.radar.type,map.radar.width-2,map.radar.height-2,0.2,teams.hues[i]);
}

this.options = {
  vocabulary: vocabulary,
  custom_map: map.map,
  soundtrack: music[~~(Math.random()*music.length)],
  weapons_store: false,
  friendly_colors: 2,
  radar_zoom: 2,
  map_size: modifier.map_size,
  starting_ship: 801,
  crystal_value: modifier.crystal_value,
  speed_mod: 1.25,
  max_players: modifier.max_players,
  ships: ships,
  choose_ship: [602,603,605,609],
  release_crystal: modifier.yeet_gems,
  hues: [colors.hue,colors.hue2],
  asteroids_strength: 2,
  crystal_drop: 0,
  max_level: 1,
  acw_allowed: true
};

var check = function(game, isWaiting, isGameOver) {
  modUtils.tick();
  if (game.step % 30 === 0) {
    teams.count = [0,0];
    for (let ship of game.ships) {
      if (!ship.custom.init){
        ship.custom.init = true;
        ship.custom.frags = 0;
        ship.custom.deaths = 0;
        setteam(ship);
        setup(ship);
        sendUI(ship, {
          id: "buy_lifes_blocker",
          visible: true,
          clickable: true,
          shortcut: String.fromCharCode(187),
          position: [65,0,10,10],
          components: []
        });
        sendUI(ship, game.custom.radar_background);
        echo(`${ship.name} spawned`);
        ship.custom.rand = ["","",""];
        ship.custom.buttons = false;
        if (isGameOver) gameover(ship);
      }
      else if (isGameOver && !ship.custom.exited) modUtils.setTimeout(function(){gameover(ship)},300);
      if (!ship.custom.joined && !isWaiting && !isGameOver) {
        joinmessage(ship);
        ship.custom.joined = true;
      }
      ship.set({idle: !!isWaiting, collider: !(isWaiting || isGameOver)})
      checkButtons(ship);
      teams.count[ship.custom.team]++;
      (ship.score != ship.custom.frags) && ship.set({score:ship.custom.frags});
      ship.emptyWeapons();
    }
  }
}, FormatTime = function(tick, forced, forceAll) {
  var array = Array(3).fill(0).map((i,j) => Math.floor((tick%(60**(j+2)))/(60**(j+1)))).reverse();
  while (array.length > forceAll && array[0] == 0) array.splice(0,1);
  forced = forced.reverse().slice(0,array.length).reverse();
  return array.map((i,j) => (i<10&&(j==0?forced[j]:!0))?"0"+i.toString():i).join(":");
}

var endgametext = ["Unknown", "Unknown"], endgamestatus = {};
var gameover = function (ship){
  ship.gameover({
    "Match status": endgametext[0],
    "Match results": endgametext[1],
    "Frags": ship.custom.frags,
    "Deaths": ship.custom.deaths,
    " ": " ",
    "#. Best killers":"Frags",
    ...endgamestatus
  });
  ship.custom.exited = true;
}

var waiting = function (game) {
  check(game, true);
  if (game.step % 30 === 0) for (let ship of game.ships){
    sendUI(ship, {
      id: "delay",
      position: [39,18,42,40],
      visible: true,
      components: [
        {type: "text",position:[2,5,80/1.5,33/1.5],value:"Waiting for more players...",color:"#cde"},
      ]
    });
    sendUI(ship, {
      id: "scoreboard",
      visible: true,
      components: [
        {type: "text",position:[15,0,70,10],value:"Waiting for more players...",color:"#cde"},
      ]
    });
  }
  if (game.step >= delay){
    checkscores(game);
    updatescoreboard(game);
    sendUI(game, {id:"delay time",visible:false});
    sendUI(game, {id:"delay",visible:false});
    this.tick = main_game;
  }
  else {
    sendUI(game, {
      id: "delay time",
      position: [45.7,26,10,7],
      visible: true,
      components: [
        {type: "text",position:[0,0,100,50],value:`${FormatTime(delay - game.step, [], 1)}`,color:"#cde"}
      ]
    });
  }
}, main_game = function(game){
  check(game);
  if (Math.min(...teams.count) == 0) finishgame(game, 2);
  else if (Math.max(...teams.points) >= modifier.kills_to_win) finishgame(game, 1);
  else if (game.step % 30 === 0){
    let time = delay+modifier.round_timer*3600;
    if (game.step < time){
      if (game.step > delay){
        sendUI(game, {
          id: "timer",
          position: [2.5,28,15,10],
          visible: true,
          components: [
            {type: "text",position:[0,0,100,50],value:`Time left: ${FormatTime(time - game.step, [false, true, true], 2)}`,color:"#cde"}
          ]
        });
      }
    } else finishgame(game, 0);
  }
  if (update){
    checkscores(game);
    updatescoreboard(game);
    update = 0;
  }
  if (game.step % 60 === 0){
    //checkteambase(game)
    updatescoreboard(game);
  }
}, finishgame = function(game, condition) {
  // conditions: 0 (time's up), 1 (reach enough kills), 2 (all one team left)
  let win;
  if (condition != 2) {
    if (teams.points[0] != teams.points[1]){
      win = teams.points.indexOf(Math.max(...teams.points));
      endgametext = `${teams.names[win]} team wins!`;
    } else endgametext = "It's a draw!";
    endgametext = [condition?`${teams.names[win]} team reaches ${modifier.kills_to_win} kills`:"Time's up!", endgametext];
  }
  else {
    win = teams.count.indexOf(0);
    if (win == -1) return;
    win = 1 - win;
    endgametext = [`All ${teams.names[1-win]} players left`, `${teams.names[win]} team wins!`];
  }
  game.ships.sort((a,b) => (b.custom.frags || 0) - (a.custom.frags || 0)).slice(0,3).forEach((ship,i) => {
    endgamestatus[(i+1)+". "+ship.name] = ship.custom.frags
  });
  game.custom.ended = true;
  game.setOpen(false);
  sendUI(game, {
    id: "timer",
    position: [2.5,28,15,10],
    visible: true,
    components: [
      {type: "text",position:[0,0,100,50],value:"Game finished!",color:"#cde"},
    ]
  });
  sendUI(game, {
    id: "end",
    position: [35,20,30,15],
    visible: true,
    components: [
      {type:"text",position:[0,0,100,50],value:endgametext[0],color:"#cde"},
      {type:"text",position:[0,50,100,50],value:endgametext[1],color:"#cde"}
    ]
  });
  echo(endgametext);
  this.tick = endgame;
}.bind(this), endgame = function (game){
  modUtils.tick();
  check(game, false, true);
};

this.tick = waiting;

function setup(ship){
  let t = ship.custom.team;
  let level = Math.trunc(ship.type/100); //level = (level<4)?4:level;
  let gems = ((modifier.round_ship_tier**2)*20)/1.5;
  let x = map.shipspawn[t].x,
  y = map.shipspawn[t].y,r=0;
  ship.set({x:x,y:y,stats:88888888,invulnerable:300,shield:999,crystals:gems});
}

function setteam(ship){
  let t;
  if ([...new Set(teams.count)].length == 1) t=teams.points.indexOf(Math.min(...teams.points));
  else t = teams.count.indexOf(Math.min(...teams.count));
  ship.custom.team = t;
  configship(ship, t);
  echo(teams.count);
}

function configship(ship,t){
  ship.set({hue:teams.hues[t],team:t,invulnerable:300,stats:88888888});
}

function rekt(ship,num){
  if (ship.shield<num){
    let val=ship.crystals + ship.shield;
    if (val < num) ship.set({kill:true});
    else ship.set({crystals:val-num,shield:0});
  }
  else ship.set({shield:ship.shield-num});
}

function isRange(a,b,c){
  return Math.min(a,b) <= c && c <= Math.max(a,b)
}

function checkteambase(game){
  for (let ship of game.ships){
    let u = 1 - ship.custom.team;
    let x = map.basedmg[u];
    let y = map.basedmg[u];
    if (isRange(x.x,x.x2,ship.x) && isRange(y.y,y.y2,ship.y)){
      rekt(ship,10*Math.trunc(ship.type/100));
      sendUI(ship, {
        id: "dang",
        position: [34,20,40,40],
        visible: true,
        components: [{type:"text",position:[0,0,80,33],value:"You are in the emeny's base - your ship will take damage!",color:"#f99e9e"}]
      });
    } else sendUI(ship, {id:"dang",visible:true});
  }
}

var scoreboard = {
  id:"scoreboard",
  visible: true,
  components: []
};

function getcolor(color){
  return `hsla(${color},100%,50%,1)`;
}

function PlayerBox(posx,posy){
  return {type:"box",position:[posx,posy-1.8,50,7],fill:"hsla(210,24.3%,29%,0.5)",width:2};
}

function Tag(indtext,param,posx,posy,hex,al,size) {
  let obj= {type: indtext,position: [posx,posy-0.5,50-(size||0),5],color: hex,align:al};
  switch(indtext) {
    case "text":
      obj.value=param;
      break;
    case "player":
      obj.id=param;
    break;
  }
  return obj;
}

function sort(arr){
  let array=[...arr],i=0;
  while (i<array.length-1) {
    if (array[i].custom.frags<array[i+1].custom.frags) {
      array[i+1]=[array[i],array[i]=array[i+1]][0];
      if (i>0) i-=2;
    }
    i++;
  }
  return array;
}

function updatescoreboard(game){
  if (game.step >= delay){
    let t=[[],[]];
    for (let ship of game.ships) t[ship.custom.team].push(ship);
    scoreboard.components = [
      { type:"box",position:[0,0,50,8],fill:getcolor(teams.hues[0])},
      { type: "text",position: [0,0,50,8],color:"#e5e5e5",value: teams.names[0]},
      { type:"box",position:[50,0,50,8],fill:getcolor(teams.hues[1])},
      { type: "text",position: [50,0,50,8],color:"#e5e5e5",value: teams.names[1]}
    ];
    let sc=[sort(t[0]),sort(t[1])],line=1;
    sc[0].slice(10);sc[1].slice(10);
    for (let i=0;i<10;i++){
      for (let j=0;j<2;j++){
        if (sc[j][i]) scoreboard.components.push(
          new Tag("text",sc[j][i].custom.frags,j*50,line*10,"#cde","right",2),
          new Tag("player",sc[j][i].id,j*50,line*10,"#cde","left")
        );
        else scoreboard.components.push({},{});
      }
      line++;
    }
    outputscoreboard(game,sc);
  }
}

function outputscoreboard(game,tm){
  let origin =[...scoreboard.components];
  for (let ship of game.ships){
    let j=0,team=tm[ship.custom.team];
    for (j=0;j<team.length;j++){
      if (ship.id === team[j].id){
        scoreboard.components.splice((j*2+ship.custom.team)*2+4,0,
          new PlayerBox(ship.custom.team*50,(j+1)*10)
        );
        break;
      }
    }
    if (j == team.length) scoreboard.components.splice((20+ship.custom.team)*2,2,
      new PlayerBox(ship.custom.team*50,90),
      new Tag("text",ship.custom.frags,ship.custom.team*50,90,ship.custom.team,"right",2),
      new Tag("player",ship.id,ship.custom.team*50,90,ship.custom.team,"left")
    );
    sendUI(ship, scoreboard);
    scoreboard.components = [...origin];
  }
}

function checkscores(game){
  if (game.step >= delay)
  sendUI(game, {
    id: "scores",
    position: [33,10,42,40],
    visible: true,
    components: [
      {type: "text",position:[2-((Math.log(teams.points[0])*Math.LOG10E+1|0)*5)/2,5,80/1.5,33/1.5],value:teams.points[0],color:getcolor(teams.hues[0])},
      {type: "text",position:[0,0,80,33],value:"-",color:"#CDE"},
      {type: "text",position:[25+((Math.log(teams.points[1])*Math.LOG10E+1|0)*5)/2,5,80/1.5,33/1.5],value:teams.points[1],color:getcolor(teams.hues[1])},
    ]
  });
}

function joinmessage(ship){
  sendUI(ship, {
    id: "join",
    position: [36,16,34,32],
    visible: true,
    components: [
      {type: "text",position:[0,0,85+3,38+3],value:`First team to ${modifier.kills_to_win} kills wins`,color:"#cde"},
      {type: "text",position:[5.5,20,80-4,33-4],value:"Good luck and have fun!",color:"#cde"},
    ]
  });
  sendUI(ship, {
    id: "map info",
    position: [2,88,24,22],
    visible: true,
    components: [
      {type: "text",position:[0,0,100,50],value:`Map: ${map.name} by ${map.author}`,color:"#cde"},
    ]
  });
  modUtils.setTimeout(function(){
    sendUI(ship, {id:"join",visible:false});
  },480);
}

function checkButtons(ship){
  let shortcut = ["5","6","7"];
  for (let i=0; i<3; i++){
    sendUI(ship, {
      id: "ship_selection_"+i,
      position: [36,26+i*7,34,18/2],
      visible: ship.custom.buttons&&ship.custom.opened,
      clickable: ship.custom.buttons&&ship.custom.opened,
      shortcut: shortcut[i],
      components: [
        {type: "box",position:[0,0,88,40*2],stroke:"#191919",fill:"#333333",width:5},
        {type: "text",position:[0,4,88/1.2,40/1.2*2],value:`     ${ship.custom.rand[i]} [${shortcut[i]}]`,color:"#cde"},
      ]
    });
  }
  sendUI(ship, {
    id: "close",
    position: [43,26+4*7,34/2,18/2],
    visible: ship.custom.buttons&&ship.custom.opened,
    clickable: ship.custom.buttons&&ship.custom.opened,
    shortcut: "4",
    components: [
      {type: "box",position:[0,0,88,40*2],stroke:"#191919",fill:"#333333",width:5},
      {type: "text",position:[0,4,88/1.2,40/1.2*2],value:"    Close [4]",color:"#cde"},
    ]
  });
  sendUI(ship, {
    id: "open",
    position: [3,33,16,20/2],
    visible: ship.custom.buttons&&!ship.custom.opened,
    clickable: ship.custom.buttons&&!ship.custom.opened,
    shortcut: "4",
    components: [
      {type: "box",position:[0,0,88,40*2],stroke:"#191919",fill:"#333333",width:5},
      {type: "text",position:[6,4,88/1.2,40/1.2*2],value:"Select ship [4]",color:"#cde"},
    ]
  });
  sendUI(ship, {
    id: "heal",
    position: [3,42,16,20/2],
    visible: ship.custom.buttons&&modifier.healer_button,
    clickable: ship.custom.buttons&&modifier.healer_button,
    shortcut: "J",
    components: [
      {type: "box",position:[0,0,88,40*2],stroke:"#191919",fill:"#333333",width:5},
      {type: "text",position:[6,4,88/1.2,40/1.2*2],value:`${(ship.healing)?"Offensive":"Healing"} [J]`,color:"#cde"},
    ]
  });
}

this.event = function(event, game){
  let ship = event.ship;
  if (ship != null) switch (event.name){
    case "ship_destroyed":
      let killer = event.killer;
      if (killer != null) {
        ship.set({collider:true});
        teams.points[killer.custom.team]++;
        killer.custom.frags++;
        echo(`${killer.name} killed ${ship.name}`);
      } else {
        echo(ship.name + " killed themselves");
        //teams.points[Math.abs(ship.team-1)]++;
      }
      ship.custom.deaths++;
      update = 1;
      ship.custom.hasbeenkilled = true;
      echo(`${teams.names[0]}:${teams.points[0]},${teams.names[1]}:${teams.points[1]}`);
      break;
    case "ship_spawned":
      if (ship.custom.hasbeenkilled === true){
        ship.custom.rand = shuffle(ship_name);
        ship.custom.buttons = true;
        ship.custom.opened = false;
        modUtils.setTimeout(function(){
          ship.custom.buttons = false;
        },540);
        ship.custom.hasbeenkilled = false;
      }
      if (ship.custom.team != null) setup(ship);
      update = 1;
      break;
    case "ui_component_clicked":
      if (ship.custom.buttons) {
        let component = event.id;
        switch (component){
          case "open": ship.custom.opened = true; break;
          case "heal": ship.set({healing:!ship.healing}); break;
          case "close": ship.custom.opened = false; break;
          default:
            if (component.startsWith("ship_selection_") && ship.custom.opened){
              let ship_code = findShipCode(ship.custom.rand[parseInt(component.replace(/^ship_selection_/,"")) || 0]);
              if (ship_code){
                if (ship.type != ship_code) ship.set({type:ship_code,stats:88888888,shield:999,collider:true});
              }
              ship.custom.opened = false;
              ship.custom.buttons = false;
            }
          break;
        }
      }
    break;
  }
};

var senko = {
  id: "senko",
  obj: "https://starblast.data.neuronality.com/mods/objects/plane.obj",
  emissive: "https://raw.githubusercontent.com/45rfew/Starblast-mods-n-objs/master/Img/senko.png",
  transparent: true
}

game.setObject({
  id:"senko",
  type:senko,
  position:{x:-840,y:750,z:-25},
  scale:{x:40*1.6,y:40,z:40},
  rotation: {x:0,y:0,z:Math.PI}
});
